<?php
/**
 * Ads.class.php
 *
 * @author FX
 * @date   18-1-2 下午9:17
 */

namespace Center;

use Common\ModuleBase;
use Common\Bridge;

class Ads extends ModuleBase
{
    protected static $_conf = [
        'db' => [
            'w' => Bridge::DB_CENTER_W,
            'r' => Bridge::DB_CENTER_R
        ],

        'table' => 'Ads',
        'fields' => [
            'Id' => self::VAR_TYPE_KEY,
            'CityId' => self::VAR_TYPE_INT,
            'ShopId' => self::VAR_TYPE_INT,
            'Title' => self::VAR_TYPE_STRING,
            'Cover' => self::VAR_TYPE_STRING,
            'Description' => self::VAR_TYPE_STRING,
            'Content' => self::VAR_TYPE_STRING,
            'ViewCount' => self::VAR_TYPE_INT,
            'StartTime' => self::VAR_TYPE_STRING,
            'EndTime' => self::VAR_TYPE_STRING,
            'Sort' => self::VAR_TYPE_INT,
            'AdFee' => self::VAR_TYPE_INT,
            'AdType' => self::VAR_TYPE_INT,
            'LinkUrl' => self::VAR_TYPE_STRING,
            'MaxCount' => self::VAR_TYPE_INT,
            'Status' => self::VAR_TYPE_INT,
            'UpdateTime' => self::VAR_TYPE_STRING,
            'CreateTime' => self::VAR_TYPE_STRING
        ],
        'mc' => Bridge::MEMCACHE_DEFAULT,
        // 可选, MC KEY, "KeyName:%d", %d会用主键ID替代
        'mckey' => 'Ads:%d',
        // 可选, 超时时间, 默认不过期
        'mctime' => 86400,
    ];

    const MC_ADS_LIST = 'Ads_List:1';
    const UPDATE_DEL_CACHE_LIST = true; // 更新是否清除列表缓存

    protected static $_cache_list_keys = [
        self::MC_ADS_LIST => self::CACHE_LIST_TYPE_MC,
    ];
    /**
     * 获取shop列表
     *
     * @param     $cityid
     * @param     $catid
     * @param int $offset
     * @param int $limit
     * @return array
     */
    public static function getAdsByCityId($cityid = 1, $time = false, $cache = true)
    {
        if ($cache) {
            $type = parent::MOD_TYPE_MEMCACHE;
        } else {
            $type = parent::MOD_TYPE_DB;
        }
        $mckey = self::MC_ADS_LIST;
        $extra = [
            'type' => $type,
            'mckey' => $mckey,
            'mtime' => 86400,
            'fields' => '*',
            'listkey' => 'Id',
            'order' => 'Sort Asc',
        ];
        $where = [
            'CityId' => $cityid,
            'Status' => 1,
        ];
        if ($time) {
            $now = date('Y-m-d H:i:s');
            $where['StartTime <='] = $now;
            $where['EndTime >'] = $now;
        }
        $ret = parent::getDataByFields($where, $extra);

        return $ret;
    }
    /**
     * @see ModuleBase::add() 新增
     * @see ModuleBase::update() 更新
     * @see ModuleBase::getInfoByIds() 按id查询
     * @see ModuleBase::getList() 条件查询
     * @see ModuleBase::delete() 删除
     */

}